﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using HtmlAgilityPack;

namespace Microhard.WeixinMP.Unities
{
    public static class StringExtension
    {
        public static string GetContentRandomImage(this string value)
        {
            //获得文章图片
            var html = HttpUtility.HtmlDecode(value);
            HtmlAgilityPack.HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            var nodes = doc.DocumentNode.SelectNodes("//img");
            string picUrl = string.Empty;
            if (nodes != null && nodes.Count > 0)
            {
                var r = new Random();
                var c = r.Next(0, nodes.Count - 1);
                picUrl = nodes[c].Attributes[@"src"].Value;
            }
            return picUrl;
        }
    }
}
